/**
  ******************************************************************************
  * @file    misc.h
  * @author  MCD Application Team
  * @brief   This file contains all the functions prototypes for the miscellaneous
  *          firmware library functions (add-on to CMSIS functions).
  ******************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MISC_H
#define __MISC_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"

/** @addtogroup STM32F4xx_StdPeriph_Driver
  * @{
  */

/** @addtogroup MISC
  * @{
  */

/* Exported types ------------------------------------------------------------*/

/** 
  * @brief  NVIC Init Structure definition  
  */
typedef struct
{
  uint8_t NVIC_IRQChannel;                    /*!< Specifies the IRQ channel to be enabled or disabled.
                                                   This parameter can be a value of @ref IRQn_Type 
                                                   (For the complete STM32 Devices IRQ Channels list, please
                                                    refer to the appropriate CMSIS device file (stm32f4xxxx.h)) */

  uint8_t NVIC_IRQChannelPreemptionPriority;  /*!< Specifies the pre-emption priority for the IRQ channel
                                                   specified in NVIC_IRQChannel. This parameter can be a value
                                                   between 0 and 15 as described in the table @ref NVIC_Priority_Table */

  uint8_t NVIC_IRQChannelSubPriority;         /*!< Specifies the subpriority level for the IRQ channel specified
                                                   in NVIC_IRQChannel. This parameter can be a value
                                                   between 0 and 15 as described in the table @ref NVIC_Priority_Table */

  FunctionalState NVIC_IRQChannelCmd;         /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
                                                   will be enabled or disabled. 
                                                   This parameter can be set either to ENABLE or DISABLE */   
} NVIC_InitTypeDef;

/* Exported constants --------------------------------------------------------*/

/** @defgroup MISC_Exported_Constants
  * @{
  */

/** @defgroup NVIC_Priority_Table 
  * @{
  */

/*
  #######################################################################################################################
  #                                   NVIC_Priority_Table
  #######################################################################################################################
  # NVIC_PriorityGroup    | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority  | Description
  #  NVIC_PriorityGroup_0 |           0-15                    |            0                | 0 bits for pre-emption priority
  #                        |                                  |           0-15               | 4 bits for subpriority
  #----------------------------------------------------------------------------------------------------------------------
  #  NVIC_PriorityGroup_1 |           0-7                     |            0                | 1 bits for pre-emption priority
  #                        |                                  |           0-15               | 3 bits for subpriority
  #----------------------------------------------------------------------------------------------------------------------
  #  NVIC_PriorityGroup_2 |           0-3                     |            0                | 2 bits for pre-emption priority
  #                        |                                  |           0-3                | 2 bits for subpriority
  #----------------------------------------------------------------------------------------------------------------------
  #  NVIC_PriorityGroup_3 |           0-1                     |            0                | 3 bits for pre-emption priority
  #                        |                                  |           0-1                | 1 bits for subpriority
  #----------------------------------------------------------------------------------------------------------------------
  #  NVIC_PriorityGroup_4 |           0                       |            0-15             | 4 bits for subpriority
  #                        |                                  |           0-15               | 0 bits for pre-emption priority
  #######################################################################################################################
*/

/**
  * @}
  */

/** @defgroup NVIC_Priority_Group 
  * @{
  */
#define NVIC_PriorityGroup_0         ((uint32_t)0x700) /*!< 0 bits for pre-emption priority
                                                            4 bits for subpriority */
#define NVIC_PriorityGroup_1         ((uint32_t)0x600) /*!< 1 bits for pre-emption priority
                                                            3 bits for subpriority */
#define NVIC_PriorityGroup_2         ((uint32_t)0x500) /*!< 2 bits for pre-emption priority
                                                            2 bits for subpriority */
#define NVIC_PriorityGroup_3         ((uint32_t)0x400) /*!< 3 bits for pre-emption priority
                                                            1 bits for subpriority */
#define NVIC_PriorityGroup_4         ((uint32_t)0x300) /*!< 4 bits for subpriority
                                                            0 bits for pre-emption priority */

/**
  * @}
  */

/** @defgroup NVIC_System_Low_Power 
  * @{
  */
#define NVIC_LP_SEVONPEND            ((uint8_t)0x10)
#define NVIC_LP_SLEEPDEEP            ((uint8_t)0x04)
#define NVIC_LP_SLEEPONEXIT          ((uint8_t)0x02)
/**
  * @}
  */

/** @defgroup NVIC_Preemption_Priority_Table 
  * @{
  */

/**
  * @}
  */

/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/

/* Exported functions --------------------------------------------------------*/

/*  Function used to set the NVIC priority table (based on the table you can find on the Cortex-M4 
    ARM User Manual) (add-on to CMSIS functions) *******************************************************/
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);

/*  Function used to initialize the NVIC peripheral (add-on to CMSIS functions) ***********************/
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);

/*  Function used to set the NVIC vector table (add-on to CMSIS functions) ****************************/
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset);

/*  Function used to configure the NVIC and the processor using CMSIS (add-on to CMSIS functions) ***/
void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState);

/*  Function used to get the specific pending interrupt enable bit status (add-on to CMSIS functions) */
ITStatus NVIC_GetPendingIRQ(IRQn_Type IRQn);

/*  Function used to set the pending status of the specified IRQ (add-on to CMSIS functions) *********/
void NVIC_SetPendingIRQ(IRQn_Type IRQn);

/*  Function used to clear the pending status of the specified IRQ (add-on to CMSIS functions) ******/
void NVIC_ClearPendingIRQ(IRQn_Type IRQn);

/*  Function used to get the active status of the specified IRQ (add-on to CMSIS functions) **********/
ITStatus NVIC_GetActive(IRQn_Type IRQn);

/*  Function used to configure the SysTick clock source (add-on to CMSIS functions) ******************/
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource);

#ifdef __cplusplus
}
#endif

#endif /* __MISC_H */

/**
  * @}
  */

/**
  * @}
  */
